package com.hsav.kcxb.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hsav.kcxb.R;
import com.hsav.kcxb.bean.PriceBean;

import java.util.List;

/**
 * Created by zhao
 */

public class PriceManager extends BaseAdapterManager<PriceBean> {

    private TextView mAmountTx;
    private TextView mPriceTx;
    private View mItemView;

    public PriceManager(int layoutId, List<PriceBean> dataList,Context context) {
        super(layoutId, dataList,context);
    }

    @Override
    public void initItemView(View itemView) {
        if(itemView!=null){
            this.mItemView = itemView;
            mAmountTx = (TextView)itemView.findViewById(R.id.tx_amount);
            mPriceTx = (TextView)itemView.findViewById(R.id.tx_price);
            mItemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int pos = (int)view.getTag();
                    Toast.makeText(mContext,"pos="+pos,Toast.LENGTH_SHORT).show();
                }
            });

            mItemView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View view, boolean hasFocus) {

                }
            });
        }
    }

    @Override
    public void bindViewData(int position) {
        if(mDataList == null || mDataList.size()<=position){
            return;
        }
        this.mItemView.setTag(position);
        if(position%3==0){
            this.mItemView.setPadding(40,0,0,0);
        }
        PriceBean priceBean = mDataList.get(position);
        if(priceBean!=null){
            mAmountTx.setText(String.valueOf(priceBean.getAmount()));
            mPriceTx.setText(String.valueOf(priceBean.getPrice()));
        }
    }


}
